<template>
	<view class="container">
		<view class="orders-list d-flex flex-column w-100" style="padding: 20rpx; padding-bottom: 0;">
			<view class="order-item" v-for="(item, index) in orders" :key="index" style="margin-bottom: 30rpx;">
				<list-cell :hover="false">
					<view class="w-100 d-flex align-items-center">
						<view class="flex-fill d-flex flex-column">
							<view class="font-size-lg text-color-base" style="margin-bottom: 20rpx;">
								{{ item.title}}
							</view>
						</view>
						<view class="font-size-lg text-color-primary" @click="delitem(item)">
							删除
						</view>
					</view>
				</list-cell>
				<list-cell :hover="false" last>
					<view class="w-100 d-flex flex-column">
						<view class="w-100 text-truncate font-size-lg text-color-base" style="margin-bottom: 20rpx;">
							{{ item.content}}
						</view>
						<view class="d-flex justify-content-between align-items-center" style="margin-bottom: 30rpx;">
							<view class="font-size-sm text-color-assist">
								{{ item.createTime }}
							</view>
							<view>
								{{ item.isAll | goodsRetrievingvalue}}
							</view>
						</view>
						
					</view>
				</list-cell>
			</view>
		</view>
	</view>
</template>

<script>
	import listCell from '@/components/list-cell/list-cell'
	import {lookNotices,updateNotice,delNotice} from '../../utils/http/index.js'
	import {mapState,mapMutations} from 'vuex'
	export default{
		components: {
			listCell
		},
		data() {
			return {
				page: 1,
				pageSize: 5,
				orders: []
			}
		},
		filters:{
			goodsRetrievingvalue(value){
				if(value == 0){
					return '系统公告'
				}else{
					return '送餐公告'
				}
			}
		},
		async onLoad() {
			if(!this.$store.getters.isLogin) {
				uni.navigateTo({url: '/pages/login/login'})
			}
			await this.getOrders(true)
		},
		async onReachBottom() {
			await this.getOrders(false)
		},
		async onPullDownRefresh() {
			await this.getOrders(true)
		},
		computed:{
			...mapState(['member'])
		},
		methods:{
			async delitem(event){
				const {data} = await delNotice({del:0,noticeId:event.id},this.member.token)
				if(data.code == 0){
					this.orders.forEach((v,i)=>{
						if(v.id == event.id){
							this.orders.splice(i,1)
						}
					})
				}
				
			},
			async getOrders(isRefresh = false) {
				uni.showLoading({
					title: '加载中'
				})
				if(isRefresh) {
					this.orders = []
					this.page = 1
				}
				let orders = await lookNotices({page:this.page,size:this.pageSize},this.member.token)
				if(orders.data.data.length){
					this.orders = this.orders.concat(orders.data.data)
					this.page += 1
				}
				console.log('orders',this.orders)
				// let rankall = rankall.map((event)=>{return event.id})
				// for (let s of rankall) {
				// 	this.readnotice(s)
				// }
				this.readnotice()
				uni.hideLoading()
			},
			async readnotice(){
				const {data} = await updateNotice({all:1,noticeId:0},this.member.token)
				console.log('已读',data)
				  let pages = getCurrentPages();//获取页面栈
				      let beforePage = pages[pages.length - 2];//上一页
				      beforePage.$vm.getlookNotices();//直接调用上一页的方法
			},
		}
	}
</script>

<style scoped>
	
</style>
